﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        #region 变量~
        string path = Environment.CurrentDirectory + "/info.txt";
        string path2= Environment.CurrentDirectory + "/info[2].txt";
        int battleship_quantity;
        int rank = 1;
        int life;
        int now_life;
        int strength;
        int now_strength;
        int now_battleship_quantity;
        bool yeah;
        int exp;
        int now_exp;
        #endregion


        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            #region 配置文件
            if (File.Exists(path))
            {
                StreamReader stream = new StreamReader(path, Encoding.Default);
                string fuck = stream.ReadToEnd();
                stream.Close();
                int.TryParse(fuck, out rank);
            }
            else
            {
                MessageBox.Show("很高兴见到你(⊙ ▽ ⊙)", "www");
            }
            #endregion

            switch (rank)
            {
                case 1:
                    battleship_quantity = 10;
                    life = 100;
                    strength = 100;
                    exp = 100;
                    progressBar2.Maximum = life;
                    progressBar3.Maximum = strength;
                    progressBar3.Maximum = exp;

                    break;

                case 2:
                    battleship_quantity = 20;
                    life = 120;
                    strength = 120;
                    exp = 120;
                    progressBar2.Maximum = life;
                    progressBar3.Maximum = strength;
                    progressBar3.Maximum = exp;
                    break;

            }
            now_life = life;
            now_strength = strength;
            now_battleship_quantity = battleship_quantity;

            yeah = false;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Pen fuck = new Pen(Color.Black);
            Point pt1 = new Point(0, 0);
            Point pt2 = new Point(894, 0);
            g.DrawLine(fuck, pt1, pt2);
            Point pt3 = new Point(893, 0);
            Point pt4 = new Point(893, 558);
            g.DrawLine(fuck, pt3, pt4);
            Point pt5 = new Point(0, 475);
            Point pt6 = new Point(894, 475);
            g.DrawLine(fuck, pt5, pt6);
            Point pt7 = new Point(0, 0);
            Point pt8 = new Point(0, 558);
            g.DrawLine(fuck, pt7, pt8);
        }      //画线~边框啦




        private void label1_Click_1(object sender, EventArgs e)
        {
            this.Close();//关闭窗口
        }

        private void label2_Click_1(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Minimized;//最小化窗口
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            string www;
            www = DateTime.Now.ToString("hh:mm:ss");
            string textt = Textbox1.Text;
            textt = textt.ToLower();

            if (yeah == false)
            {
                if (textt.IndexOf("hello?anybody here?") >= 0)
                {
                    textBox2.Text = textBox2.Text + "[" + www + "] " + "你成功的挑起了一场战争Orz\r\n";
                    yeah = true;
                }
            }
            else
            {
                if (textt.IndexOf("fire") >= 0)
                {
                    if (now_battleship_quantity != 0 || now_strength != 0)
                    {
                        textBox2.Text = textBox2.Text + "[" + www + "] " + "你成功地烧毁了一架战舰\r\n";
                        now_battleship_quantity = now_battleship_quantity - 1;
                        now_strength = now_strength - 10;
                        now_exp = now_exp + 10;
                    }
                }
                if (now_battleship_quantity == 0)
                {
                    MessageBox.Show("你赢得了这场战争");
                    yeah = false;
                }
                if (textt.IndexOf("exit") >= 0)
                {
                    textBox2.Text = textBox2.Text+"["+www+"] " + "你成功地逃跑了\r\n";
                    yeah = false;
                }
            }

            Textbox1.Text = "";

        }


        private void timer1_Tick(object sender, EventArgs e)
        {

            label1.Text = "剩余战舰量:" + "『" + now_battleship_quantity + "』";
            label2.Text = "等级:" + "『" + rank + "』";
            progressBar2.Value = now_life;
            progressBar3.Value = now_strength;
            progressBar1.Value = now_exp;
            if (progressBar1.Value == progressBar1.Maximum)
            {
                rank = rank + 1;
                now_exp = 0;
            }



        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (now_strength != strength && yeah==true  )
            {
                now_strength = now_strength + 1;
            }

        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            File.WriteAllText(path, rank+"");
            File.WriteAllText(path2, now_exp+"")
        }
    }


}


